using UniversalAdminSystem.Domian.UserManagement.ValueObj;
using UniversalAdminSystem.Domian.Core.ValueObjects;

namespace UniversalAdminSystem.Domian.UserManagement.Entities;

public class UserInfo
{
    /// <summary>
    /// 信息唯一标识
    /// </summary>
    public UserInfoId UserInfoId { get; private set; } = null!;

    /// <summary>
    /// 用户性别
    /// </summary>
    public UserGender? Gender { get; private set; }

    /// <summary>
    /// 用户年龄
    /// </summary>
    public int? Age { get; private set; }

    /// <summary>
    /// 用户地址
    /// </summary>
    public string? Address { get; private set; }

    /// <summary>
    /// 用户姓名
    /// </summary>
    public string? Name { get; private set; }

    /// <summary>
    /// 用户电话
    /// </summary>
    public string? Phone { get; private set; }

    /// <summary>
    /// 供Efcore使用
    /// </summary>
    private UserInfo() { }

    /// <summary>
    /// 创建用户信息的工厂方法
    /// </summary>
    /// <param name="name">姓名</param>
    /// <param name="gender">性别</param>
    /// <param name="phone">电话</param>
    /// <param name="address">地址</param>
    /// <returns></returns>
    public static UserInfo CreateUserInfo(string? name = null, UserGender? gender = null, string? phone = null, string? address = null)
    {
        var userInfo = new UserInfo
        {
            UserInfoId = UserInfoId.Create(Guid.NewGuid()),
            Name = name,
            Gender = gender,
            Phone = phone,
            Address = address
        };
        return userInfo;
    }

    public UserInfo UpdateUserInfo(UserGender? gender, int? age, string? addrss)
    {
        if (age < 0)
        {
            throw new ArgumentException("出现了!时间穿越!(年龄错误)");
        }
        
        Gender = gender;
        Age = age;
        Address = addrss;

        return this;
    }
}